package com.example.pro1.controller.lian.oldController;

import com.example.pro1.entity.lian.oldPojo.*;

import com.example.pro1.service.lian.oldService.customeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/superRootOld")
@ResponseBody
/*解决跨域问题*/
@CrossOrigin
public class superRootControllerOld {
    /*实现超级管理员功能*/
    @Autowired
    com.example.pro1.service.lian.oldService.goodInfoService goodInfoService;
    @Autowired
    customeService customerService;
    @Autowired
    com.example.pro1.service.lian.oldService.rootService rootService;
    @Autowired
    com.example.pro1.service.lian.oldService.superRootService superRootService;

    /*返回表一的数据*/
    @GetMapping("/getT1Info")
    public List<t1> getT1Info(){
        return goodInfoService.getT1Info();
    }

    /*返回表二的信息*/
    @GetMapping("/getT2Info")
    public List<t2> getT2Info(){
        return goodInfoService.getT2Info();
    }

    /*返回表三的数据*/
    @GetMapping("/getT3Info")
    public List<t3t4> getT3Info(){
        ArrayList<t3t4> list = new ArrayList<>();
        t3t4 d1 = new t3t4("新增用户",1,3,0,0,1,2,0);
        t3t4 d2 = new t3t4("活跃用户",5,2,4,3,2,6,7);
        list.add(d1);
        list.add(d2);
        return list;
    }


    /*返回表四的数据*/
    @GetMapping("/getT4Info")
    public List<t3t4> getT4Info(){
        ArrayList<t3t4> list = new ArrayList<>();
        t3t4 d1 = new t3t4("食品",5,7,4,3,2,3,0);
        t3t4 d2 = new t3t4("粮油调味",3,1,2,1,3,1,5);
        t3t4 d3 = new t3t4("酒",0,1,0,0,1,0,1);
        t3t4 d4 = new t3t4("饮料",2,1,3,0,0,1,4);
        list.add(d1);
        list.add(d2);
        list.add(d3);
        list.add(d4);
        return list;
    }

    /*查询商品数量*/
    @GetMapping("/getGoodsNum")
    public Integer getGoodsNum(){
        return goodInfoService.getGoodsNum();
    }

    /*查询customer数量*/
    @GetMapping("/getCustomerNum")
    public Integer getCustomerNum(){
        return customerService.getCustomerNums();
    }


    /*查询root数量*/
    @GetMapping("/getRootNum")
    public Integer getRootNum(){
        return rootService.getRootNums();
    }

    /*查询superRoot数量*/
    @GetMapping("/getSuperRootNum")
    public Integer getSuperRootNum(){
        return superRootService.getSuperRootNums();
    }

    /*查询商品信息*/
    @GetMapping("/getGoodsInfo")
    public List<goodOld> getGoodsInfo(@RequestParam Map<String,Object> map){
        /*通过service方法来查询*/
        return goodInfoService.getGoodsInfo(map);
    }

    /*查询商品详细信息*/
    @GetMapping("/getGoodsWithSort")
    public List<goodWithSort> getGoodsWithSort(@RequestParam Map<String,Object> map){
        /*返回商品的详细信息*/
        List<goodWithSort> goodWithSort = goodInfoService.getGoodWithSort(map);
        List<goodWithSort> returnList = new ArrayList<>();
        for (com.example.pro1.entity.lian.oldPojo.goodWithSort withSort : goodWithSort) {
            if (withSort.getGId()!=null){
                returnList.add(withSort);
            }
        }
        return returnList;
    }

    /*返回一级分类和二级分类的连接信息*/
    @GetMapping("/getGfsWithGss")
    public List<gfsWithGss> getGfsWithGss(@RequestParam Map<String,Object> map){
        return goodInfoService.getGfsWithGss(map);
    }

    /*商品添加*/
    @PostMapping("/addOneGood")
    public boolean addOneGood( @RequestParam("Imagefile") MultipartFile file,@RequestParam Map<String,Object> map){
        if (map.containsKey("gssId")){
            String s = goodInfoService.upLoadImage(file);
            /*如果图片保存失败，我们也没有必要继续了*/
            if (s!=""){
                map.put("gImageSrc",s);
                return goodInfoService.addOneGood(map);
            }
            return false;
        }
        return false;
    }

    /*已有img进行商品添加*/
    @PostMapping("/addOneGoodWithImg")
    public boolean addOneGoodWithImg(@RequestParam Map<String,Object> map){
        return goodInfoService.addOneGood(map);
    }

    /*查询商品已有一级分类*/
    @GetMapping("/getGoodsFirstSorts")
    public List<goodFirstSort> getGoodsFirstSorts(@RequestParam Map<String,Object> map){
        return goodInfoService.getGoodFirstSort(map);
    }

    /*查询商品已有二级分类*/
    @GetMapping("/getGoodsSecondSorts")
    public List<goodSecondSort> getGoodsSecondSorts(@RequestParam Map<String,Object> map){
        return goodInfoService.getGoodSecondSort(map);
    }

    /*添加商品一级分类*/
    @GetMapping("/insertGoodFirstSort")
    public boolean insertGoodFirstSorts(@RequestParam Map<String,Object> map){
        return goodInfoService.addFirstSort(map);
    }


    /*添加商品二级分类*/
    @GetMapping("/insertGoodSecondSort")
    public boolean insertGoodSecondSort(@RequestParam Map<String,Object> map){
        return goodInfoService.addSecondSort(map);
    }

    /*删除商品一级分类*/
    @GetMapping("/deleteGoodFirstSort")
    public boolean deleteGoodFirstSort(@RequestParam Map<String,Object> map){
        return goodInfoService.deleteFirstSort(map);
    }

    /*删除商品二级分类*/
    @GetMapping("/deleteGoodSecondSort")
    public boolean deleteGoodSecondSort(@RequestParam Map<String,Object> map){
        return goodInfoService.deleteSecondSort(map);
    }

    /*商品修改*/
    @GetMapping("/updateGoods")
    public boolean updateGoodsInfo(@RequestParam Map<String,Object> map){
        return goodInfoService.updateGoodsInfo(map);
    }

    /*根据ID修改商品信息*/
    @GetMapping("/updateGoodsById")
    public boolean updateGoodsById(@RequestParam Map<String,Object> map){
        return goodInfoService.updateGoodsById(map);
    }


    /*商品通过id删除*/
    @GetMapping("/deleteGoodById")
    public boolean deleteGoodsInfo(@RequestParam Map<String,Object> map){
        return goodInfoService.deleteOneGoodById(map);
    }


    /*管理员信息维护*/
    /*添加管理员*/
    @GetMapping("/addOneRoot")
    public boolean addOneRoot(@RequestParam Map<String,Object> map){
        return rootService.addOneRooter(map);
    }

    /*删除管理员*/
    @GetMapping("/deleteOneRoot")
    public boolean deleteRootById(@RequestParam Map<String,Object> map){
        return rootService.deleteOneRooterById(map);
    }


    /*修改管理员信息*/
    @GetMapping("/updateOneRoot")
    public boolean updateRootInfo(@RequestParam Map<String,Object> map){
        return rootService.updateRooterInfo(map);
    }

    /*通过Id修改管理员信息*/
    @GetMapping("/updateRootById")
    public boolean updateRootById(@RequestParam Map<String,Object> map){
        return rootService.updateRootById(map);
    }

    /*查询管理员信息*/
    @GetMapping("/getRootInfo")
    public List<rootOld> getRootInfo(@RequestParam Map<String,Object> map){
        return rootService.getRootersInfo(map);
    }


    /*客户信息维护*/
    /*添加新客户*/
    @GetMapping("/addOneCustomer")
    public boolean getCustomer(@RequestParam Map<String,Object> map){
        return customerService.addOneCustomer(map);
    }

    /*删除客户*/
    @GetMapping("/deleteOneCustomer")
    public boolean deleteCustomer(@RequestParam Map<String,Object> map){
        return customerService.deleteOneCustomerById(map);
    }

    /*修改客户信息*/
    @GetMapping("/updateCustomer")
    public boolean updateCustomer(@RequestParam Map<String,Object> map){
        return customerService.updateCustomerInfo(map);
    }

    /*根据ID修改客户信息*/
    @GetMapping("/updateCustomerById")
    public boolean updateCustomerById(@RequestParam Map<String,Object> map){
        return customerService.updateCustomerById(map);
    }

    /*查询客户信息*/
    @GetMapping("/getCustomerInfo")
    public List<customerOld> getCustomerInfo(@RequestParam Map<String,Object> map){
        return customerService.getCustomersInfo(map);
    }


}
